package com.hbsx.why.utils.refresh;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * Created by liub on 2017/8/21 15:18.
 */

public class PullRecycleView extends RecyclerView implements Pullable {
    //  private PullRecycleView pullRecycleView=null;
    private boolean pullDownEnable = true; //下拉刷新开关
    private boolean pullUpEnable = true; //上拉刷新开关
    //private RecycleViewListener recycleViewListener = null;

    public PullRecycleView(Context context) {
        super(context);
    }

    public PullRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PullRecycleView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthSpec, expandSpec);
    }

    @Override
    public boolean canPullDown() {
        if (!pullDownEnable) {
            return false;
        }
        // 判断 scrollView 当前滚动位置在顶部
        if (getScrollY() == 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean canPullUp() {
        if (!pullUpEnable) {
            return false;
        }
        // 判断scrollview 滑动到底部
        if (getChildAt(0).getHeight() - getHeight()
                == getScrollY()) {
            return true;
        }
        return false;
    }



    public boolean isPullDownEnable() {
        return pullDownEnable;
    }

    public void setPullDownEnable(boolean pullDownEnable) {
        this.pullDownEnable = pullDownEnable;
    }

    public boolean isPullUpEnable() {
        return pullUpEnable;
    }

    public void setPullUpEnable(boolean pullUpEnable) {
        this.pullUpEnable = pullUpEnable;
    }

}
